class ['a] triangle (som1:'a) (som2:'a) (som3:'a) =
object
  val mutable s1 = som1
  val mutable s2 = som2
  val mutable s3 = som3
  method s1 = s1
  method s2 = s2
  method s3 = s3
  method set_s1 som = s1 <- som
  method set_s2 som = s2 <- som
  method set_s3 som = s3 <- som
end

let make s1 s2 s3 = new triangle s1 s2 s3

let pointlist step img = (* build the point list *)
  let i = ref 0 in
  let j = ref 0 in
  let lp = ref [] in
  begin
    while !i<(img#get_width-step) do
      begin
	while !j<(img#get_height-step) do
	  begin
	    lp := (Point.make !i !j (img#get_coord_heights !i !j)) :: !lp;
	    j := !j + step;
	  end
	done;
	j := 0;
	i := !i + step;
      end
    done;
  end;
  (!lp)

let trilist step img = (* build the triangle list *)
  let i = ref 0 in
  let j = ref 0 in
  let lt = ref [] in
  begin
    while !i<(img#get_width-step) do
      begin
	while !j<(img#get_height-step) do
	  begin
	    lt := (make 
		     (Point.make (!i) (!j) (img#get_coord_heights (!i) (!j)))
		     (Point.make ((!i)+step) (!j) (img#get_coord_heights
						     ((!i)+step) (!j))) 
		     (Point.make ((!i)+step) ((!j)+step)
			(img#get_coord_heights ((!i)+step) ((!j)+step))) :: !lt);
	    lt := (make
		     (Point.make (!i) (!j+step) (img#get_coord_heights (!i)
						   (!j+step)))
		     (Point.make (!i) (!j) (img#get_coord_heights (!i) (!j)))
		     (Point.make (!i+step) (!j+step)
			(img#get_coord_heights (!i+step) (!j+step)))) :: !lt; 	
	    j := !j + step;
	  end
	done;
	j := 0;
	i := !i + step;
      end
    done;
  end;
  (!lt)
